/**
 * @description User 数据模式
 * @author malin
 */

const validate = require('./_validator')

const SCHEMA = {
    type: 'object',
    properties: {
        userName: {
            type: 'string',
            pattern: '^[a-zA-Z]\\w{4,}$',
            minLength: 5,
            maxLength: 255
        },
        password: {
            type: 'string',
            minLength: 6,
            maxLength: 16
        },
        newPassword: {
            type: 'string',
            minLength: 6,
            maxLength: 16
        },
        nickName: {
            type: 'string',
            maxLength: 20
        },
        picture: {
            type: 'string',
            maxLength: 255
        },
        city: {
            type: 'string',
            minLength: 2,
            maxLength: 10
        },
        gender: {
            type: 'number',
            minimum: 1,
            maximum: 3
        }
    }
}

/**
 * user模式验证器（在中间件里执行）
 * @param {*} schema 
 * @param {*} data 
 */
function userValidator(data = {}) {
    return validate(SCHEMA, data)
}

module.exports = userValidator
